package com.android.smsmessing;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import com.android.smsmessing.adapter.SMSAdapter;
import com.android.smsmessing.adapter.SMSInboxAdapter;
import com.android.smsmessing.adapter.SMSAdapter.ViewHolder;
import com.android.smsmessing.model.PeopleVO;
import com.android.smsmessing.model.SMSInboxVO;
import com.android.smsmessing.provider.SMS;
import com.android.smsmessing.services.PeopleService;
import com.android.smsmessing.services.SMSService;
import com.android.smsmessing.utils.DateUtils;
import com.android.smsmessing.utils.ListUtils;
import com.android.smsmessing.utils.StringUtils;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class SMSInboxActivity extends ListActivity {
	  SMSInboxAdapter smsInboxAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	       smsInboxAdapter = new SMSInboxAdapter(this);
	       initData(this,smsInboxAdapter);
	       setListAdapter(smsInboxAdapter);
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		SMSInboxAdapter.ViewHolder holder  = (SMSInboxAdapter.ViewHolder) v.getTag();
		Bundle bundle = new Bundle();
		bundle.putString("number",  holder.smsInboxVO.mobile);
		//打开新窗体
		Intent intent = new Intent();
		intent.setClass(SMSInboxActivity.this, SMSSendActivity.class);
		intent.putExtras(bundle);
		startActivity(intent);
	}
	
	/**
	 * 初始化数据
	 * @param context
	 */
	public void initData(Context context,SMSInboxAdapter smsInboxAdapter){
		HashMap<Integer,SMSInboxVO> keyMap = SMSService.getInstance().getSMSInboxsToMap(context);
		smsInboxAdapter.resertData(keyMap);
		smsInboxAdapter.notifyDataSetChanged();
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		initData(this,smsInboxAdapter);
	}
	
}
